package com.gomtel.smartdevice.ui.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import com.gomtel.smartdevice.R;
import com.gomtel.smartdevice.global.WatchApplication;

/**
 * Created by Administrator on 2018/5/26 0026.
 */

public class GriddingView extends View {

    Paint paint;  //绘图

    public GriddingView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        paint = new Paint();
        paint.setColor(context.getResources().getColor(R.color.grey2));
        paint.setStrokeJoin(Paint.Join.ROUND);
        paint.setStrokeCap(Paint.Cap.ROUND);
        paint.setStrokeWidth(3);
    }

    public GriddingView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public GriddingView(Context context) {
        super(context);
        // TODO Auto-generated constructor stub

    }

    /**
     * 绘制网格线
     */
    protected void onDraw(Canvas canvas) {
        canvas.drawColor(WatchApplication.getInstance().getResources().getColor(R.color.gray_min));
        //canvas.drawCircle(100, 100, 90, paint);
        final int width = getWidth();  //hdpi 480x800
        final int height = getHeight();
        final int edgeWidth = 10;
        final int space = 30;   //长宽间隔
        int vertz = 0;
        int hortz = 0;
        for (int i = 0; i < 100; i++) {
            canvas.drawLine(0, vertz, width, vertz, paint);
            canvas.drawLine(hortz, 0, hortz, height, paint);
            vertz += space;
            hortz += space;
        }
    }

    private void drawBacgroundLine(Canvas canvas ){
        int length = getWidth() / 7 + 1;// 横长
        int bound = getHeight() / 6;// 竖长
        Paint paint = new Paint();
        paint.setColor(Color.BLACK);
        paint.setStrokeWidth(1);
        for (int i = 0; i < bound; i++) {
            for (int j = 0; j < length; j++) {
                canvas.drawLine(j * length, 0, j * length, bound, paint);
                canvas.drawLine(0, i * bound, length, i * bound, paint);
            }
        }
    }

}
